package com.yeyks.commonReference.service.other.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeyks.commonReference.service.other.SmsHistoryService;
import com.yeyks.consumer.dal.domain.UserInfo;
import com.yeyks.consumer.service.UserInfoService;
import com.yeyks.other.dal.dao.SmsHistoryMapper;
import com.yeyks.other.dal.domain.SmsHistory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yun
 * @since 2019-06-25
 */
@Service
@Slf4j
public class SmsHistoryServiceImpl extends ServiceImpl<SmsHistoryMapper, SmsHistory> implements SmsHistoryService {
    @Autowired
    private SmsHistoryMapper smsHistoryMapper;
    @Autowired
    private UserInfoService userInfoService;

    public Integer insertByPhoneDesc(String phone, String desc, String code) {
        UserInfo userInfo = userInfoService.selectUseInfoPhone(phone);
        if (userInfo == null) {
            log.info("通过手机号获取不到该用户{}", phone);
        }
        SmsHistory smsHistory = new SmsHistory();
        smsHistory.setContents(code);
        smsHistory.setPhone(phone);
        smsHistory.setSmsType(desc);
        if (userInfo != null) {
            smsHistory.setAccountId(userInfo.getId().longValue());
        }
        smsHistory.setCreateTime(new Date());
        return smsHistoryMapper.insertSelective(smsHistory);
    }

    public Integer insertSelective(SmsHistory smsHistory) {
        return baseMapper.insert(smsHistory);
    }


}
